/**
 * Created by dukes on 2015/11/4.
 */
//module game{
    class PopulationItemRender extends eui.ItemRenderer{
        public constructor(){
            super();
            this.skinName = "pet.PopulationRenderSkin";
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAdded, this);
            this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
        }

        private onTrack(evt:egret.TouchEvent){
            var id = parseInt(this.data.userId);
            if( id ){
                DateScene.getInstance().forceDisplay(this.data);
            }
        }

        private onAdded(evt:egret.Event){
            this.img_track.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTrack, this);
        }

        private onRemoved(evt:egret.Event){
            this.img_track.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTrack, this);
        }
        public dataChanged(){
            super.dataChanged();
            this.lab_name.text = LimitStringLen(this.data.userName);
            this.lab_desc.text = "为你贡献了"+this.data.contribution+"个赞";
            this.group_rank.text = (this.itemIndex)+1+"";
            if( this.data.userFigureurl )
                this.img_head.source = this.data.userFigureurl;
        }

        private img_track:eui.Image;
        private group_rank:eui.BitmapLabel;
        private img_head:eui.Image;
        private lab_name:eui.Label;
        private lab_desc:eui.Label;
        public partAdded(name:string, instance:any){
            super.partAdded(name,instance);
            if( name == "img_track"){
                this.img_track = instance;
            }else if( name == "group_rank"){
                this.group_rank = instance;
            }else if( name == "img_head"){
                this.img_head = instance;
            }else if( name == "lab_name"){
                this.lab_name = instance;
            }else if( name == "lab_desc"){
                this.lab_desc = instance;
            }
        }
    }
//}